home *** CD-ROM | disk | FTP | other *** search
- Path: alpha2.csd.uwm.edu!peterk
- From: peterk@alpha2.csd.uwm.edu (Peter J Kleczka)
- Newsgroups: comp.lang.c
- Subject: Crash Proofing?
- Date: 9 Mar 1996 17:36:46 GMT
- Organization: Information & Media Technologies, University of Wisconsin - Milwaukee
- Distribution: world
- Message-ID: <4hsfje$rbr@uwm.edu>
- NNTP-Posting-Host: 129.89.169.2
-
- Hi all
- I'm new to C programing and am trying to re-write a program
- I did in pascal in C. When I wrote the pascal program I got
- caught up in the details of getting the program to work and
- consequentially readability of the code and user-friendlyness
- suffered......
-
- The program I'm working on (below) works fine as long
- as the user enters an integer.....but it gets caught in an
- endless loop between the functions: firstmenu() and firstchoice()
- when I enter, say, 5.5 instead of an integer
-
- it's unlikely that the user would enter anything but an integer
- when presented with integer choices...but I want to make the
- code uncrashable .....what can I do if anything to make it
- so that the program doesnt do wierd things if the user enters
- the wrong thing here?
-
- thanks in advance
- (please email peterk@csd.uwm.edu) with your suggestions
- :)
-
- /* prototype for the C version of block schedule program */
-
- #include <stdio.h>
-
- main(){
-
- firstmenu(); /* call to programs main menu */
- firstchoice(); /* call to function which gets users choice from main menu */
-
- } /* end main */
-
- firstmenu(){ /* list users options */
-
- printf ("\t\t\t *** M A I N M E N U ***\n\n");
- printf ("Please choose one of the following:\n");
- printf ("\t1. Instructions\n");
- printf ("\t2. Enter a new schedule\n");
- printf ("\t3. Edit or Review schedule\n");
- printf ("\t4. Quit\n\n");
-
- } /* end firstmenu */
-
- firstchoice(){ /* get users choice and branch to appropos function */
-
- unsigned choice;
-
- scanf ("%d", &choice);
- /* while loop till user enters integer 1-4 */
- while (choice !=1 && choice != 2 && choice != 3 && choice !=4){
- printf("You entered %d ... please choose a number between 1-4\n\n", choice);
- firstmenu(); /* remind user of appropos choices */
- scanf("%d", &choice);
- } /* end while */
-
- switch (choice){
- case 1: Instructions(); /* branch to instructions function */
-
- break;
-
- case 2: Entersch(); /* branch to enter schedule function */
-
- break;
-
- case 3: Editsch(); /* branch to edit schedule function */
-
- break;
-
- case 4: Goodbye(); /* branch to goodbye function */
-
- break;
-
- default: printf (" Error trap in firstchoice function, choice not 1-4\n");
-
- break;
-
- }/* end switch */
- }/* end firstchoice */
-
- Instructions(){ /* give user instructions on how to use this program */
-
- printf ("\n\n\tCool instructions are comming soon\n\n");
- firstmenu(); /* remind user of choices again */
- firstchoice(); /* let user make another choice */
-
- } /* end Instructions */
-
- Entersch(){ /* let user enter a schedule */
-
- printf("\n\n\tSoon youll be able to enter schedules\n\n");
- firstmenu(); /* remind user of choices again */
- firstchoice(); /* let user make another choice */
-
- } /* end Entersch */
-
- Editsch(){ /* let user edit schedules */
-
- printf("\n\n\tSoon youll be able to edit schedules\n\n");
- firstmenu(); /* remind user of choices again */
- firstchoice(); /* let user make another choice */
-
- } /* endit Editsch */
-
- Goodbye(){ /* tell user the program has ended */
-
- printf("\n\n\tBye now, ya all come back now hear\n\n");
-
- } /* end Goodbye */
-
-
-